import { modalPropsType } from "@/constants/types";
import { Modal, Form, Input, Radio } from "antd";
import React from "react";

const {Item} = Form;
const rules = [{required: true, message: '此项必填'}];
const labelCol = {span: 4}

const CompanyCertify = ({title, visible, currentRow, onCancel, onSubmit}: modalPropsType) => {
  const [form] = Form.useForm();

  const handleSubmit = async () => {
    const res = await form.validateFields();
    onSubmit({
      ...res,
      customerId: currentRow?.id
    });
  }

  return (
    <Modal
      title={title}
      open={visible}
      onCancel={onCancel}
      onOk={handleSubmit}
      width="550px"
      maskClosable={false}
    >
      <Form form={form} labelCol={labelCol}>
        <Item label="是否通过" name="checkStatus" rules={rules}>
            <Radio.Group options={[{label: '认证通过', value: 1}, {label: '认证不通过', value: 0}]} />
        </Item>
        <Item noStyle shouldUpdate={(prev, next) => prev.checkStatus !== next.checkStatus}>
          {({getFieldValue}) => {
            const checkStatus = getFieldValue('checkStatus');
            return (
              <Item label="备注" name="remark" rules={String(checkStatus) === '0' ? rules : undefined}>
                <Input.TextArea rows={3} />
              </Item>
            )
          }}
        </Item>
      </Form>
    </Modal>
  );
}
export default CompanyCertify;